import request from "../../utils/request"
// pages/index/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        bannerList:[],//初始化轮播图数据
        recommendList: [],//初始化推荐列表数据
        topList:[],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    async onLoad(options) {
        let bannerListData = await  request('/banner',{type:2});//请求轮播图数据
        let recommendListData = await request('/personalized',{limit: 10})//请求推荐歌曲数据
        //请求排行榜数据
        let allTopListData = await request('/toplist')
        // console.log(allTopListData);
        let topList = allTopListData.list.slice(0, 4)
        let topListDetail = []
        for (let item of topList) {
            let detailList = await request(`/playlist/detail?id=${item.id}`, { limit: 10 })
            // console.log(detailList);
            topListDetail.push({name: detailList.playlist.name, tracks: detailList.playlist.tracks.slice(0, 3)})
    }
    
      this.setData({
        bannerList: bannerListData.banners,
        recommendList: recommendListData.result,
        topList: topListDetail,
      })
    },
    toDailyRecommend(){
        wx.navigateTo({
            url: '/pages/dailyRecommend/dailyRecommend',
          })
  },
    toSearch(){
        wx.navigateTo({
          url: '/pages/search/search',
        })
    },

    //页面刷新
    // onPullDownRefresh(){
        
    // },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})